﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using LM.Negocio.Objetos;

namespace LM.Repositorios.Maps
{
    public class GaragemMap : EntityTypeConfiguration<Garagem>
    {
        public GaragemMap()
        {
            this.HasKey(c => c.Id);
            this.Property(c => c.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity).HasColumnName("Id");
            
            this.Property(c => c.Nome).HasColumnName("Nome").IsRequired();
            this.Property(c => c.Cnpj).HasColumnName("Cnpj");
            this.Property(c => c.InscricaoMunicipal).HasColumnName("InscricaoMunicipal");

            HasMany(p => p.Vagas)
                .WithRequired(s => s.Garagem)
                .HasForeignKey(s => s.IdGaragem).WillCascadeOnDelete(true);

            HasMany(x => x.Telefones).WithMany().Map(map =>
            {
                map.ToTable("GARAGEM_TELEFONE");
                map.MapLeftKey("IdGaragem");
                map.MapRightKey("IdTelefone");
            });

            this.ToTable("GARAGEM");
        }
    }
}
